<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/layout/common.xhtml">
	<ui:define name="body">
		<h:form id="form" acceptcharset="ISO-8859-1">
			<f:metadata>
				<f:viewParam name="param" value="#{lancamentoProducaoBean.param}"/>
			</f:metadata>

			<p:remoteCommand name="updateServico" update="form:panelServico" />
			<p:remoteCommand name="updateItemOrc" update=":formItemOrcamento" />
			<p:remoteCommand name="updateTableLancamento" update="dataTableLancar, concluirLancamento, lancandoPanel, form" />

			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="#{msg['massai.comum.pesquisar']}" 
						ajax="false" immediate="true" action="lancarServicoProducao" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            <p:commandButton value="#{msg['massai.comum.novo']}" 
		            	ajax="false" immediate="true" action="lancarServicoProducaoCadastro" />
				</f:facet>
			</p:toolbar>
			<p:panel header="#{msg['massai.lancarServicoProducao.header']}">
				<h:panelGrid cellspacing="5" style="width: 100%;">
					<h:panelGroup>
						<fieldset>
							<legend><h:outputText value="#{msg['massai.lancarServicoProducao.dadosPlanilha']}" /></legend>
							<h:panelGrid>
								<h:panelGrid columns="4">
									<h:panelGrid>
										<h:outputLabel value="#{msg['massai.manterGrupoProducao.codigo']}" for="codPlanilha" />
										<p:inputText
											value="#{genericUtilBean.completarZerosEsquerda(lancamentoProducaoBean.planilha.id, 8)}" 
											id="codPlanilha" disabled="true" readonly="true" style="text-align: right; width: 60px;" />
									</h:panelGrid>

									<h:panelGrid>
										<p:outputLabel value="#{msg['massai.lancarServicoProducao.tipoFolha']}" for="tipoFolha" />
										<p:selectOneMenu tabindex="1" id="tipoFolha" style="width: 120px;"
											disabled="#{lancamentoProducaoBean.planilha.id ne null}" 
											value="#{lancamentoProducaoBean.tipoFolha}" required="true" 
											requiredMessage="#{msg['massai.lancarServicoProducao.tipoFolha']} é obrigatório(a).">
											<f:selectItems value="#{lancamentoProducaoBean.tipoFolha()}" />
											
										</p:selectOneMenu>
									</h:panelGrid>

									<h:panelGrid>
										<p:outputLabel value="#{msg['massai.lancarServicoProducao.competencia']}" for="competencia" />
										<p:inputMask tabindex="2" value="#{lancamentoProducaoBean.planilha.competencia}"
											disabled="#{lancamentoProducaoBean.planilha.id ne null}"
											readonly="#{lancamentoProducaoBean.planilha.id ne null}" 
											mask="99/9999" id="competencia" style="width: 80px; text-align: right;" converter="competenciaConverter"
											required="true" requiredMessage="#{msg['massai.lancarServicoProducao.competencia']} é obrigatório(a)." />
									</h:panelGrid>

									<h:panelGrid>
										<p:outputLabel value="#{msg['massai.manterGrupoProducao.obra']}" for="obra" />
										<p:selectOneMenu tabindex="3" id="obra" value="#{lancamentoProducaoBean.obra}" converter="entityConverter"
											style="width: 300px;" required="true" requiredMessage="Obra é obrigatório(a)."
											disabled="#{lancamentoProducaoBean.planilha.id ne null}">
											<f:selectItems value="#{lancamentoProducaoBean.obrasVinculadasUsuario()}" />
											<p:ajax event="change" global="false" listener="#{lancamentoProducaoBean.carregaFuncionarios()}" />
										</p:selectOneMenu>
									</h:panelGrid>
								</h:panelGrid>

								<h:panelGrid>
									<h:outputLabel value="#{msg['massai.lancarServicoProducao.observacoesPlanilha']}" for="observ" />
									<p:inputTextarea
										tabindex="4" disabled="#{lancamentoProducaoBean.planilha.finalizada or lancamentoProducaoBean.obraBloquada}" 
										readonly="#{lancamentoProducaoBean.planilha.finalizada}"
										id="observ" rows="2" cols="90" autoResize="false" 
										placeholder="Observações da planilha..."
										value="#{lancamentoProducaoBean.planilha.observacao}">
										<p:ajax event="change" global="false" />
									</p:inputTextarea>
								</h:panelGrid>
								
								<h:panelGrid rendered="#{lancamentoProducaoBean.verificaObservacao()}">
									<h:outputLabel style="color: #f00;" value="#{msg['massai.lancarServicoProducao.observacoesAnalise']}" for="observAnalise" />
									<p:inputTextarea
										disabled="true" readonly="true"
										id="observAnalise" rows="2" cols="80" autoResize="false" 
										placeholder="#{msg['massai.comum.placeholder']}"
										value="#{lancamentoProducaoBean.planilha.observacaoRevisao}" />
								</h:panelGrid>
							</h:panelGrid>
							
							<h:panelGrid>
								<h:panelGrid>
									<p:commandButton tabindex="5"
										rendered="#{lancamentoProducaoBean.planilha.id eq null}"
										value="#{msg['massai.lancarServicoProducao.salvarPlanilha']}"  
										update="form,itemLancamentoPanel,dataTableLancamentos,:messages" 
										actionListener="#{lancamentoProducaoBean.salvarPlanilha()}"
										oncomplete="updateServico()" ajax="false" />
								</h:panelGrid>
							</h:panelGrid>
						</fieldset>
					</h:panelGroup>

					<h:panelGroup id="itemLancamentoPanel" 
						rendered="#{lancamentoProducaoBean.planilha.id ne null and not lancamentoProducaoBean.planilha.finalizada}">
						<p:spacer height="20" />

						<fieldset>
							<legend><h:outputText value="#{msg['massai.lancarServicoProducao.itemLancamento']}" /></legend>
							<h:panelGrid>
								<h:panelGrid columns="2">
									<h:panelGrid>
										<h:outputLabel value="#{msg['massai.lancarServicoProducao.funcionario']}" for="funcionario" />
										<p:selectOneMenu id="funcionario" style="width: 497px;" tabindex="6"
											value="#{lancamentoProducaoBean.funcionario}"
											converter="entityConverter" disabled="#{lancamentoProducaoBean.lancando || lancamentoProducaoBean.obraBloquada}">
											<f:selectItems value="#{lancamentoProducaoBean.funcionarios()}" />
											
										</p:selectOneMenu>
									</h:panelGrid>

									<h:panelGrid id="regimePanel">
										<h:outputLabel value="#{msg['massai.lancarServicoProducao.regime']}" for="regime" />
										<p:selectOneMenu id="regime" style="width: 150px;" tabindex="7" 
											value="#{lancamentoProducaoBean.regime}"
											disabled="#{lancamentoProducaoBean.lancando || lancamentoProducaoBean.obraBloquada}">
											<f:selectItems value="#{lancamentoProducaoBean.regimes()}" />
											<f:ajax event="change" listener="#{lancamentoProducaoBean.carregaServicos()}" render="form:panelServico" />
										</p:selectOneMenu>
									</h:panelGrid>
								</h:panelGrid>
								
								<h:panelGrid id="panelServico" cellpadding="0" cellspacing="0">
									<h:panelGrid columns="2" rendered="#{lancamentoProducaoBean.verificaRegimeNormal()}">
										<h:panelGrid>
											<h:outputLabel value="#{msg['massai.lancarServicoProducao.servico']}" for="servico" />
											<p:inputText id="servico" style="width: 250px;" 
												value="#{lancamentoProducaoBean.servicoRegimeNormal.itemServico.descricao}"
												label="#{msg['massai.lancarServicoProducao.servico']}" 
												disabled="true" readonly="true" />
										</h:panelGrid>

										<h:panelGrid>
											<h:outputLabel value="#{msg['massai.lancarServicoProducao.valorPerc']}" for="percent" />
											<p:inputText id="percent" style="width: 120px; text-align: right;" tabindex="8"
												label="#{msg['massai.lancarServicoProducao.valorPerc']}" 
												maxlength="8" disabled="#{lancamentoProducaoBean.obraBloquada}" 
												readonly="#{lancamentoProducaoBean.obraBloquada}" onkeypress="return numberOnlyCurrency(this, event)"
												value="#{lancamentoProducaoBean.itemLancamento.valorPercent}">
												<p:ajax event="change" listener="#{lancamentoProducaoBean.validaValorPercent()}" update=":messages,percent" />
												<f:convertNumber pattern="#,##0.0000" 
													maxFractionDigits="4" minFractionDigits="4" type="number" />
											</p:inputText>
										</h:panelGrid>
									</h:panelGrid>
									
									<h:panelGrid rendered="#{lancamentoProducaoBean.verificaRegimeGratificao()}">
										<h:panelGrid>
											<h:outputLabel value="#{msg['massai.lancarServicoProducao.valorTotalGratificacao']}" for="valorGrat" />
											<p:inputText id="valorGrat" style="width: 170px; text-align: right;" 
												value="#{lancamentoProducaoBean.valorGratificacao}" onkeypress="return numberOnlyCurrency(this, event)"
												label="#{msg['massai.lancarServicoProducao.valorTotalGratificacao']}" 
												disabled="#{lancamentoProducaoBean.obraBloquada}" readonly="#{lancamentoProducaoBean.obraBloquada}">
												<p:ajax event="change" global="false" listener="#{lancamentoProducaoBean.recalculaValorGratificacao()}" update="dataTableLancar,valorGrat" />
												<f:convertNumber pattern="#,##0.0000" 
													maxFractionDigits="4" minFractionDigits="4" type="number" />
											</p:inputText>
										</h:panelGrid>

										<h:panelGrid>
											<h:outputLabel value="#{msg['massai.lancarServicoProducao.valorPerc']}" for="percentGrat" />
											<p:inputText id="percentGrat" style="width: 170px; text-align: right;" tabindex="8"
												label="#{msg['massai.lancarServicoProducao.valorPerc']}" 
												maxlength="8" disabled="#{lancamentoProducaoBean.obraBloquada}" 
												readonly="#{lancamentoProducaoBean.obraBloquada}" onkeypress="return numberOnlyCurrency(this, event)"
												value="#{lancamentoProducaoBean.itemLancamento.valorPercent}">
												<p:ajax event="change" global="false" listener="#{lancamentoProducaoBean.validaValorPercent()}" update=":messages,percentGrat" />
												<f:convertNumber pattern="#,##0.0000" 
													maxFractionDigits="4" minFractionDigits="4" type="number" />
											</p:inputText>
										</h:panelGrid>
									</h:panelGrid>

									<h:panelGrid rendered="#{lancamentoProducaoBean.verificaRegimeProducao()}">
										<h:panelGrid columns="2">
											<h:panelGrid>
												<h:outputLabel value="#{msg['massai.lancarServicoProducao.itemServiço']}" />
												<p:inputText style="width: 145px; text-align: right;" id="codigoItemPlanilha"
													value="#{lancamentoProducaoBean.itemPlanilha.itemServico.nivel}" 
													label="#{msg['massai.manterGrupoProducao.codigo']}" disabled="true">
													<p:ajax event="change" 
														listener="#{lancamentoProducaoBean.obterItemPlanilhaPorCodigoServico()}" 
														update="codigoItemPlanilha, itemServico, valorUnit, :messages" />
												</p:inputText>
											</h:panelGrid>
											<h:panelGrid>
												<p:spacer height="12" />
												<h:panelGroup>
													<p:inputText 
														value="#{lancamentoProducaoBean.itemPlanilha.itemServico.descricao}"
														id="itemServico" label="#{msg['massai.lancarServicoProducao.itemServiço']}"
														disabled="true" readonly="true" style="width: 425px; margin-right: 3px;" />
													<p:commandButton value=". . ." style="margin-left:3px;" type="button"
														onclick="PF('servicoDlg').show();" tabindex="9" 
														disabled="#{lancamentoProducaoBean.obraBloquada}" readonly="#{lancamentoProducaoBean.obraBloquada}" />
												</h:panelGroup>
											</h:panelGrid>
										</h:panelGrid>

										<h:panelGrid columns="3" rendered="#{lancamentoProducaoBean.itemPlanilha.itemServico ne null || lancamentoProducaoBean.itemPlanilha.itemServico.id.intValue() > 0}">
											<h:panelGrid>
												<h:outputLabel value="#{msg['massai.lancarServicoProducao.valorUnit']}" />
												<p:inputText
													value="#{lancamentoProducaoBean.itemPlanilha.valor}" 
													label="#{msg['massai.lancarServicoProducao.valorUnit']}" id="valorUnit"
													style="width: 120px; text-align: right;" disabled="true" readonly="true">
													<f:convertNumber pattern="#,##0.0000" currencySymbol="R$"
														maxFractionDigits="4" minFractionDigits="4" type="number" />
												</p:inputText>
											</h:panelGrid>

											<h:panelGrid>
												<h:outputLabel value="#{msg['massai.lancarServicoProducao.quantidade']}" />
												<p:inputText
													id="quantidade" tabindex="10"
													value="#{lancamentoProducaoBean.itemLancamento.quantidade}"
													label="#{msg['massai.lancarServicoProducao.quantidade']}"
													style="width: 120px; text-align: right;" maxlength="13" onkeypress="return numberOnlyCurrency(this, event)"
													disabled="#{lancamentoProducaoBean.obraBloquada}" readonly="#{lancamentoProducaoBean.obraBloquada}">
													<f:convertNumber pattern="#,##0.00" maxFractionDigits="2" minFractionDigits="2" type="number" />
													<p:ajax event="blur" update="quantidade,totalServico" global="false"
														listener="#{lancamentoProducaoBean.calculaTotal()}" />
												</p:inputText>
											</h:panelGrid>

											<h:panelGrid id="totalServico">
												<h:outputLabel value="#{msg['massai.lancarServicoProducao.valorTotal']}" />
												<p:inputText 
													value="#{lancamentoProducaoBean.itemLancamento.total}"
													label="#{msg['massai.lancarServicoProducao.valorTotal']}"
													style="width: 120px; text-align: right;" disabled="true" readonly="true">
													<f:convertNumber pattern="#,##0.0000" currencySymbol="R$"
														maxFractionDigits="4" minFractionDigits="4" type="number" />
												</p:inputText>
											</h:panelGrid>
										</h:panelGrid>
									</h:panelGrid>

									<h:panelGrid rendered="#{lancamentoProducaoBean.regime ne null}">
										<h:panelGrid>
											<p:outputLabel value="#{msg['massai.lancarServicoProducao.observacoes']}" for="observacaoLancamento" />
											<p:inputTextarea tabindex="11" placeholder="Observações do lançamento..." 
												id="observacaoLancamento" value="#{lancamentoProducaoBean.itemLancamento.observacao}" 
												rows="2" cols="90" autoResize="false" disabled="#{lancamentoProducaoBean.obraBloquada}" 
												readonly="#{lancamentoProducaoBean.obraBloquada}">
												<p:ajax event="change" global="false" />
											</p:inputTextarea>
										</h:panelGrid>
									</h:panelGrid>

									<h:panelGrid columns="2" rendered="#{lancamentoProducaoBean.regime ne null}">
										<h:panelGrid>
											<h:outputLabel value="#{msg['massai.lancarServicoProducao.itemOrcamento']}" for="itemOrcamento" />
											<p:inputText id="codItemOrcamento" style="width: 150px; margin-right: 5px;" 
												value="#{lancamentoProducaoBean.itemOrcamentoAutoComplete.cdReferencia}"
												disabled="true" readonly="true" />
										</h:panelGrid>
										<h:panelGrid>
											<p:spacer height="12" />
											<h:panelGroup>
												<p:inputText id="itemOrcamento"
													value="#{lancamentoProducaoBean.itemOrcamentoAutoComplete.dePlanilha}" 
													label="#{msg['massai.lancarServicoProducao.itemOrcamento']}"
													disabled="true" readonly="true" style="width: 425px; margin-right: 3px;" />
												<p:commandButton value=". . ." style="margin-left:3px;" type="button"
													onclick="PF('itemOrcamentoDlg').show();" tabindex="12"
													disabled="#{lancamentoProducaoBean.obraBloquada}"
													readonly="#{lancamentoProducaoBean.obraBloquada}" />
											</h:panelGroup>
										</h:panelGrid>
									</h:panelGrid>
								</h:panelGrid>
							</h:panelGrid>
							
							<h:panelGrid>
								<h:panelGrid>
									<p:commandButton tabindex="13"
										value="#{msg['massai.lancarServicoProducao.lancar']}"  
										update="form,dataTableLancar, :messages" 
										actionListener="#{lancamentoProducaoBean.realizarLancamento()}"
										oncomplete="updateTableLancamento()" rendered="#{not lancamentoProducaoBean.obraBloquada}" />
								</h:panelGrid>
							</h:panelGrid>
						</fieldset>
						
						<p:spacer height="10" />
					</h:panelGroup>
					
					<h:panelGroup id="lancandoPanel" rendered="#{lancamentoProducaoBean.lancando and not lancamentoProducaoBean.obraBloquada}">
						<p:dataTable id="dataTableLancar"
							style="margin-top: 15px;" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
							value="#{lancamentoProducaoBean.lancamento.listaItensLancamento}" var="item" sortMode="multiple" rows="10" paginator="true"
			                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
			                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false"
			                rowIndexVar="row">

							<f:facet name="header">
								<h:outputText value="#{lancamentoProducaoBean.lancamento.funcionario.nome}" />
							</f:facet>

							<p:column headerText="#{msg['massai.lancarServicoProducao.regime']}" width="90">
								<h:outputText value="#{lancamentoProducaoBean.lancamento.regime.descricao}" />
							</p:column>
	
							<p:column headerText="#{msg['massai.lancarServicoProducao.itemServiço']}">
								<h:outputText value="#{genericUtilBean.completarZerosEsquerda(item.itemPlanilha.itemServico.nivel, 6)} - #{item.itemPlanilha.itemServico.descricao}" />
							</p:column>
	
							<p:column headerText="#{msg['massai.itemServico.unidadeMedida']}" width="80">
								<h:outputText value="#{item.itemPlanilha.itemServico.unidadeMedida ne null ? item.itemPlanilha.itemServico.unidadeMedida.sigla : '-'}" />
							</p:column>
							
							<p:column headerText="#{msg['massai.lancarServicoProducao.quantidade']}" width="70">
								<h:outputText value="#{item.quantidade}">
									<f:convertNumber pattern="#,##0.00" 
										maxFractionDigits="2" minFractionDigits="2" type="number" />
								</h:outputText>
							</p:column>
							
							<p:column headerText="#{msg['massai.lancarServicoProducao.valorUnit']}" width="80">
								<h:outputText value="#{item.itemPlanilha.valor}">
									<f:convertNumber pattern="R$ #,##0.0000" currencySymbol="R$" 
										maxFractionDigits="4" minFractionDigits="4" type="number" />
								</h:outputText>
							</p:column>
	
							<p:column headerText="#{msg['massai.lancarServicoProducao.valorTotal']}" width="80">
								<h:outputText value="#{item.total}">
									<f:convertNumber pattern="R$ #,##0.0000" currencySymbol="R$" 
										maxFractionDigits="4" minFractionDigits="4" type="number" />
								</h:outputText>
							</p:column>
	
							<p:column headerText="#{msg['massai.lancarServicoProducao.valorPerc']}" width="65">
								<h:outputText value="#{lancamentoProducaoBean.decimalFormat('#,##0.0000%', item.valorPercent)}" />
							</p:column>
	
							<p:column headerText="#{msg['massai.lancarServicoProducao.itemOrcamento']}" width="100">
								<h:outputText value="#{item.itemOrcamento.cdReferencia}" />
							</p:column>
							
							<p:column headerText="#{msg['massai.lancarServicoProducao.observacoes']}">
								<h:outputText value="#{item.observacao}" />
							</p:column>
	
							<p:column headerText="#{msg['massai.comum.excluir']}" width="42" style="text-align: center;">
								<p:commandLink onclick="if (! window.confirm('Deseja excluir esse registro?') ) {return false}" 
									actionListener="#{lancamentoProducaoBean.removerItemLancamento(row)}" update=":form">
									<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_remove.png" 
										width="16" height="16" border="0" name="#{msg['massai.comum.excluir']}" 
										title="#{msg['massai.comum.excluir']}" alt="#{msg['massai.comum.excluir']}" />
								</p:commandLink>
							</p:column>

							<p:columnGroup type="footer">
					            <p:row>
					                <p:column colspan="5" style="text-align:right" footerText="#{msg['massai.lancarServicoProducao.totais']}" />
					                <p:column footerText="#{lancamentoProducaoBean.decimalFormat('R$ #,##0.00', lancamentoProducaoBean.lancamento.totalValor)}" />
					                <p:column style="text-align: left" footerText="#{lancamentoProducaoBean.decimalFormat('#,##0.0000%',lancamentoProducaoBean.lancamento.totalPercent)}" />
					                <p:column colspan="3" />
					            </p:row>
					        </p:columnGroup>
						</p:dataTable>
	
						<h:panelGrid width="100%" id="concluirLancamento">
							<p:commandButton tabindex="14"
								onclick="if (! window.confirm('Deseja concluir o lançamento?') ) {return false}" 
								value="#{msg['massai.lancarServicoProducao.concluirLancamento']}" 
								style="float: right;" actionListener="#{lancamentoProducaoBean.concluirLancamento()}"
								update=":form,:messages" />
						</h:panelGrid>
					</h:panelGroup>

					<p:panel header="#{msg['massai.lancarServicoProducao.lancamentosHeader']}"
						rendered="#{lancamentoProducaoBean.lancamentos.size() ne 0}">

						<ui:repeat var="lancamento" value="#{lancamentoProducaoBean.lancamentos}">

							<p:dataTable rendered="#{lancamentoProducaoBean.planilha.id ne null}" 
								value="#{lancamento.listaItensLancamento}" var="item">

								<f:facet name="header">
									<h:outputText value="#{lancamento.regime.descricao} - ( #{lancamento.funcionario.codTotvs} - #{lancamento.funcionario.funcao} ) #{lancamento.funcionario.nome}" />
									<p:commandLink style="text-decoration: none;"
										rendered="#{not lancamento.planilha.finalizada and not lancamentoProducaoBean.obraBloquada}" 
										actionListener="#{lancamentoProducaoBean.editLancamento(lancamento)}" update=":form" >
										<img src="#{facesContext.externalContext.requestContextPath}/imagens/ico_edit.png" 
											width="16" height="16" border="0" name="#{msg['massai.comum.editar']}" alt="#{msg['massai.comum.editar']}" 
											style="margin:1px 0 0 10px; vertical-align:middle; text-decoration: none !important; border: none;" />
									</p:commandLink>
								</f:facet>

								<p:column headerText="#{msg['massai.lancarServicoProducao.itemServiço']}" width="280">
									<h:outputText 
										value="#{item.itemPlanilha.itemServico.descricao}" />
								</p:column>
								
								<p:column headerText="#{msg['massai.itemServico.unidadeMedida']}">
									<h:outputText value="#{item.itemPlanilha.itemServico.unidadeMedida ne null ? item.itemPlanilha.itemServico.unidadeMedida.sigla : '-'}" />
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.quantidade']}">
									<h:outputText value="#{item.quantidade}">
										<f:convertNumber pattern="#,##0.00" 
											maxFractionDigits="2" minFractionDigits="2" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.valorUnit']}">
									<h:outputText value="#{item.itemPlanilha.valor}">
										<f:convertNumber pattern="R$ #,##0.0000" currencySymbol="R$" 
											maxFractionDigits="4" minFractionDigits="4" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.valorTotal']}">
									<h:outputText value="#{item.total}">
										<f:convertNumber pattern="R$ #,##0.0000" currencySymbol="R$" 
											maxFractionDigits="2" minFractionDigits="2" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.valorPerc']}">
									<h:outputText value="#{item.valorPercent}">
										<f:convertNumber pattern="#,##0.0000%" 
											maxFractionDigits="4" minFractionDigits="4" type="number" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.itemOrcamento']}">
									<h:outputText value="#{item.itemOrcamento.cdReferencia}" />
								</p:column>
								
								<p:column headerText="#{msg['massai.lancarServicoProducao.observacoes']}">
									<h:outputText value="#{item.observacao}" />
								</p:column>
								
								<p:columnGroup type="footer">
						            <p:row>
						                <p:column colspan="4" style="text-align:right" footerText="#{msg['massai.lancarServicoProducao.totais']}" />
						                <p:column footerText="#{lancamentoProducaoBean.decimalFormat('R$ #,##0.00', lancamento.totalValor)}" />
						                <p:column style="text-align: left" footerText="#{lancamentoProducaoBean.decimalFormat('#,##0.0000%', lancamento.totalPercent)}" />
						                <p:column colspan="2" />
						            </p:row>
						        </p:columnGroup>
							</p:dataTable>
							
							<p:spacer height="20" />

						</ui:repeat>
					</p:panel>
				</h:panelGrid>
			</p:panel>
			<p:toolbar>
				<f:facet name="left">
					<p:commandButton value="#{msg['massai.comum.pesquisar']}" tabindex="15"
						ajax="false" immediate="true" action="lancarServicoProducao" />
					<span class="ui-separator">
		                <span class="ui-icon ui-icon-grip-dotted-vertical" />
		            </span>
		            <p:commandButton value="#{msg['massai.comum.novo']}" tabindex="16" 
		            	ajax="false" immediate="true" action="lancarServicoProducaoCadastro" />
				</f:facet>
			</p:toolbar>
		</h:form>

		<p:dialog header="#{msg['massai.lancarServicoProducao.obras']}" 
			id="obraDlg" widgetVar="obraDlg" resizable="false" modal="true" width="70%" showEffect="fade" appendToBody="true">
			<h:form id="formObra" acceptcharset="ISO-8859-1">
				<h:messages id="msgObra" showDetail="false" styleClass="tagMessages" layout="list" infoClass="info" errorClass="error" warnClass="warn" />
			
				<h:panelGroup style="padding: 15px;">
					<fieldset style="padding: 10px;">
						<legend><h:outputText value="#{msg['massai.comum.filtroPesquisa']}" /></legend>
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.lancarServicoProducao.descricaoObra']}" />
							<p:inputText value="#{lancamentoProducaoBean.obraModal.nomeFantasia}" 
								style="width: 300px;" maxlength="255" />
						</h:panelGrid>
					</fieldset>

					<h:panelGrid width="100%">
						<p:commandButton value="#{msg['massai.comum.pesquisar']}" ajax="true" style="margin: 5px 0; float: right;"
							actionListener="#{lancamentoProducaoBean.pesquisaObraModal()}" update="formObra" />
					</h:panelGrid>

					<p:dataTable id="dataTableObra" style="margin-top: 15px;" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
						value="#{lancamentoProducaoBean.obrasModal}" var="obra" sortMode="multiple" rows="5" paginator="true"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">

						<p:column headerText="#{msg['massai.manterGrupoProducao.codigo']}" width="80" sortBy="#{obra.codigoColigada}">
							<h:outputText value="#{genericUtilBean.completarZerosEsquerda(obra.codigo_totvs, 6)}" />
						</p:column>

						<p:column headerText="#{msg['massai.manterGrupoProducao.obra']}" sortBy="#{obra.nomeFantasia}">
							<h:outputText value="#{obra.nomeFantasia}" />
						</p:column>

						<p:column headerText="#{msg['massai.manterGrupoProducao.selecionar']}" width="30" style="text-align: center;">
							<p:commandLink actionListener="#{lancamentoProducaoBean.selecionaObra(obra)}" 
									update=":form:codObra,:form:descObra,:form:funcionario,:messages,:formItemOrcamento" 
									oncomplete="PF('obraDlg').hide();">
								<h:graphicImage value="/imagens/passed.gif" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
				</h:panelGroup>
			</h:form>
	    </p:dialog>

	    <p:dialog header="#{msg['massai.lancarServicoProducao.itemOrcamento']}" 
			id="itemOrcamentoDlg" widgetVar="itemOrcamentoDlg" position="center top" 
			resizable="false" modal="true" width="70%" showEffect="fade" appendToBody="true"
			onShow="carregaItensOrc()" style="margin-top: 30px;" closeOnEscape="true">
			<h:form id="formItemOrcamento" acceptcharset="ISO-8859-1">
				<p:remoteCommand name="carregaItensOrc" update="formItemOrcamento" actionListener="#{lancamentoProducaoBean.carregaItensOrcamento()}" />
				<h:messages id="msgItemOrc" showDetail="false" styleClass="tagMessages" layout="list" infoClass="info" errorClass="error" warnClass="warn" />

				<p:panel header="#{msg['massai.lancarServicoProducao.itemOrcamento']}">
					<h:panelGrid columns="2">
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.unidadeMedida.descricao']}" />
							<p:inputText value="#{lancamentoProducaoBean.itemOrcamentoModal.dePlanilha}" style="width: 300px;" />
						</h:panelGrid>
						
						<h:panelGrid>
							<p:spacer height="11" />
							<p:commandButton value="#{msg['massai.comum.pesquisar']}" ajax="true" 
								actionListener="#{lancamentoProducaoBean.carregaItensOrcamento()}" 
								update="formItemOrcamento,msgItemOrc" />
						</h:panelGrid>
					</h:panelGrid>
				</p:panel>
			
				<h:panelGroup style="padding: 15px;">
					<p:dataTable id="dataTableItemOrc" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
						value="#{lancamentoProducaoBean.listaItensOrcPorObra}" var="item" sortMode="multiple" rows="10" paginator="true"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">

						<p:column headerText="#{msg['massai.lancarServicoProducao.codItemOrc']}" width="120" sortBy="#{item.cdReferencia}">
							<h:outputText value="#{item.cdReferencia}" />
						</p:column>

						<p:column headerText="#{msg['massai.unidadeMedida.descricao']}" sortBy="#{item.dePlanilha}">
							<h:outputText value="#{item.dePlanilha}" />
						</p:column>

						<p:column headerText="#{msg['massai.manterGrupoProducao.selecionar']}" width="30" style="text-align: center;">
							<p:commandLink rendered="#{item.cdTabela.intValue() > 0}" 
								actionListener="#{lancamentoProducaoBean.selecionaItemOrc(item)}" 
								update=":form:codItemOrcamento,:form:itemOrcamento,:messages" 
								oncomplete="PF('itemOrcamentoDlg').hide();">
								<h:graphicImage value="/imagens/passed.gif" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
				</h:panelGroup>
			</h:form>
	    </p:dialog>
	    
	    <p:dialog header="#{msg['massai.itemServico.header']}" 
			id="servicoDlg" widgetVar="servicoDlg" resizable="false" modal="true" width="70%" 
			showEffect="fade" appendToBody="true" onShow="carregaServicos()" position="center top" style="margin-top: 30px;"
			closeOnEscape="true">
			<h:form id="formServico" acceptcharset="ISO-8859-1">
				<p:remoteCommand name="carregaServicos" update="formServico, msgServico" actionListener="#{lancamentoProducaoBean.carregaServicos()}" />
				<h:messages id="msgServico" showDetail="false" styleClass="tagMessages" layout="list" infoClass="info" errorClass="error" warnClass="warn" />
				
				<p:panel header="#{msg['massai.itemServico.header']}">
					<h:panelGrid columns="2">
						<h:panelGrid>
							<h:outputLabel value="#{msg['massai.unidadeMedida.descricao']}" />
							<p:inputText value="#{lancamentoProducaoBean.itemPlanilhaModal.itemServico.descricao}" style="width: 300px;" />
						</h:panelGrid>
						
						<h:panelGrid>
							<p:spacer height="11" />
							<p:commandButton value="#{msg['massai.comum.pesquisar']}" ajax="true" 
								actionListener="#{lancamentoProducaoBean.carregaServicos()}" 
								update="formServico,msgServico" />
						</h:panelGrid>
					</h:panelGrid>
				</p:panel>

				<h:panelGroup style="padding: 15px;">
					<p:dataTable id="dataTableServico" emptyMessage="#{msg['massai.comum.emptyMessage']}" 
						value="#{lancamentoProducaoBean.listaItensPlanilha}" var="item" sortMode="multiple" rows="10" paginator="true"
		                paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
		                currentPageReportTemplate="({currentPage} de {totalPages})" paginatorPosition="bottom" paginatorAlwaysVisible="false">

						<p:column headerText="#{msg['massai.manterGrupoProducao.nivel']}" width="70" sortBy="#{item.itemServico.nivel}">
							<h:outputText value="#{item.itemServico.nivel}" />
						</p:column>

						<p:column headerText="#{msg['massai.itemServico.descricao']}" sortBy="#{item.itemServico.descricao}">
							<h:outputText value="#{item.itemServico.descricao}" />
						</p:column>
						
						<p:column headerText="#{msg['massai.itemServico.unidadeMedida']}" sortBy="#{item.itemServico.unidadeMedida.descricao}">
							<h:outputText value="#{item.itemServico.unidadeMedida.descricao}" />
						</p:column>
						
						<p:column headerText="#{msg['massai.manterGrupoProducao.valorUnit']}" sortBy="#{item.valor}">
							<h:outputText value="#{item.valor}">
								<f:convertNumber pattern="#,##0.0000" 
									maxFractionDigits="4" minFractionDigits="4" type="number" />
							</h:outputText>
						</p:column>

						<p:column headerText="#{msg['massai.manterGrupoProducao.selecionar']}" width="30" style="text-align: center;">
							<p:commandLink actionListener="#{lancamentoProducaoBean.selecionaServico(item)}" 
									update=":form:codigoItemPlanilha,:form:itemServico,:form:valorUnit, :form:totalServico" 
									oncomplete="PF('servicoDlg').hide();">
								<h:graphicImage value="/imagens/passed.gif" />
							</p:commandLink>
						</p:column>
					</p:dataTable>
				</h:panelGroup>
			</h:form>
	    </p:dialog>
	</ui:define>
</ui:composition>
</html>